package com.hhit.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhit.mapper.ItemsMapper;
import com.hhit.pojo.Items;
import com.hhit.pojo.ItemsExample;
import com.hhit.service.ItemsService;

@Service
public class ItemsServiceImp implements ItemsService{
	
	@Autowired
	private ItemsMapper im;
	@Autowired
	private ItemsExample ie;
	
	/**
	 * 查询所有记录
	 */
	@Override
	public List<Items> findAll() {
		// TODO Auto-generated method stub
		List<Items> alllist = im.selectByExample(null);
		return alllist;
	}
	
	/**
	 * 按名称查询
	 */
	@Override
	public List<Items> findByName(Items items) {
		// TODO Auto-generated method stub
		ie.clear();
		ie.createCriteria().andNameEqualTo(items.getName());
		List<Items> namelist = im.selectByExample(ie);
		return namelist;
	}
	
	/**
	 * 保存记录
	 */
	@Override
	public void save(Items items) {
		// TODO Auto-generated method stub
		im.insert(items);
	}
	/**
	 * 删除记录
	 */
	@Override
	public void delete(Items items) {
		// TODO Auto-generated method stub
		im.deleteByPrimaryKey(items.getId());
	}
	/**
	 * 更新记录
	 */
	@Override
	public void update(Items items) {
		// TODO Auto-generated method stub
		Items it =findById(items);
		items.setCreatetime(it.getCreatetime());
		ie.clear();
		ie.createCriteria().andIdEqualTo(items.getId());
		im.updateByExample(items, ie);
	}
	
	/**
	 * 根据主键查找记录
	 */
	@Override
	public Items findById(Items items) {
		// TODO Auto-generated method stub
		return im.selectByPrimaryKey(items.getId());
	}
	
}
